// 工具函数
const serialize = params => {
  const results = []
  for (const [key, value] of Object.entries(params)) {
    results.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
  }

  return results.join('&')
  // ['username=yumm', 'age=12']
  // username = yumm & age=12
}

// www.baidu.com&
// 给URL添加参数
const addURLData = (url, data) => {
  if (!data) return ''
  const mark = url.includes('?') ? '&' : '?'
  return `${mark}${data}`
}



// 序列化成JSON格式的字符串
const serializeJSON = data => {
  return JSON.stringify(data)
}

export { serialize, addURLData, serializeJSON }